package br.com.naybee.domain.loginbs;

import org.springframework.stereotype.Service;

import br.com.naybee.framework.client.dao.DaoImpl;
import br.com.naybee.framework.client.models.ListModel;
import br.com.naybee.framework.client.models.Model;
import br.com.naybee.framework.client.models.Models;
import br.com.naybee.framework.client.utils.CryptUtil;

@Service
public  class LoginBs extends DaoImpl{

	public Model realizarLogin(Model param) {
		return Models.newModel().add("return", autenticarUsuario(list("login-usuario.sql"), param));
	}

	private boolean autenticarUsuario(ListModel listModel, Model passWord) {
		for (Model model : listModel) {
			String passWordDecrypt = CryptUtil.decrypt(model.getStr("senha"));
			if (passWordDecrypt.equals(passWord.getStr("senha"))) {
				return true;
			}
		}
		return false;
	}
}
